<template lang="pug">
  .page
    .title.mb-15.font-24
      span.mr-20 HRDC客户信息——{{customerInfo.name}}
      Button(@click="gotoBack") 返回列表
    .tab-style-hrdc
      Tabs(type="card" :value="currentTab" :animated="false" @on-click="chooseTab")
        TabPane(label="基本信息" name="1")
          .stepContent(v-if="detailCurrent === '1'")
            tab_1(:customerBusinesstype_arr="customerBusinesstype_arr" :customerInfo="customerInfo" :sizeArr="sizeArr" :characterArr="characterArr")
        TabPane(label="联系人信息" name="2")
          .stepContent(v-if="detailCurrent === '2'")
            tab_2(:customerId="customerId" :contact_arr="contact_arr" @get-list="getContactList")
        TabPane(label="预算信息" name="3")
          .stepContent(v-if="detailCurrent === '3'")
            tab_3(:budgetList="budgetList" @get-list="getBudgetList")
        TabPane(label="需求信息" name="4")
          .stepContent(v-if="detailCurrent === '4'")
            tab_4(:requirementList="requirementList" @get-D="get2DDiagnoseInfo" @get-list="getRequirementList")
        TabPane(label="方案信息" name="5")
          .stepContent(v-if="detailCurrent === '5'")
            tab_5(:planList="planList" @get-list="getPlanList")
        TabPane(label="合作信息" name="6")
          .stepContent(v-if="detailCurrent === '6'")
            tab_6(:bargainList="bargainList" @get-list="getBargainList")
        TabPane(label="签约信息" name="7")
          .stepContent(v-if="detailCurrent === '7'")
            tab_7(:salesContractList="salesContractList" @get-list="getSalesContractList")
        TabPane(label="待分配项目" name="11")
          .stepContent(v-if="detailCurrent === '11'")
            tab_11(:toAllocationList="toAllocationList")
        TabPane(label="待交付项目" name="8")
          .stepContent(v-if="detailCurrent === '8'")
            tab_8(:toDeliveryList="toDeliveryList")
        TabPane(label="已交付项目" name="9")
          .stepContent(v-if="detailCurrent === '9'")
            tab_9(:deliveryList="deliveryList")
        TabPane(label="课程项目评价反馈" name="10")
          .stepContent(v-if="detailCurrent === '10'")
            tab_10(:feedBackList="feedBackList")
        TabPane(label="沟通记录" name="12")
          .stepContent(v-if="detailCurrent === '12'")
            tab_12(:communicationList="communicationList" :communicationTotal="communicationTotal")
    diagnose(ref="diagnose" :requirementId="requirementId" :customerName="customerName")
</template>

<script>
import HRDCCustomerApi from '@/api/HRDCCustomer.api.js'
import dataApi from '@/api/data.js'

import tab_1 from './tabs/tab-1.vue'
import tab_2 from './tabs/tab-2.vue'
import tab_3 from './tabs/tab-3.vue'
import tab_4 from './tabs/tab-4.vue'
import tab_5 from './tabs/tab-5.vue'
import tab_6 from './tabs/tab-6.vue'
import tab_7 from './tabs/tab-7.vue'
import tab_8 from './tabs/tab-8.vue'
import tab_9 from './tabs/tab-9.vue'
import tab_10 from './tabs/tab-10.vue'
import tab_11 from './tabs/tab-11.vue'
import tab_12 from './tabs/tab-12.vue'

import diagnose from '@/view/oti-center/sales/demand-A/modal/2D.vue'
import detailMixin from './detailMixin.js'

export default {
  mixins: [detailMixin],
  data () {
    return {
      requirementId: '', // 需求id
      customerName: '', // 客户名称
      customerId: '',
      customerInfo: {},
      currentTab: '1',
      detailCurrent: '1',
      contact_arr: [], // 联系人列表
      customerBusinesstype_arr: [], // 行业
      sizeArr: [], // 公司规模
      characterArr: [], // 企业性质
      communicationtype: [], // 沟通方式
      communicationList: [], // 留言列表
      communicationTotal: 0,
      budgetList: [], // 预算列表
      requirementList: [], // 需求列表
      planList: [], // 方案列表
      bargainList: [], // 合作信息列表
      salesContractList: [], // 签约信息列表
      toAllocationList: [], // 待分配交付信息
      toDeliveryList: [], // 待交付信息列表
      deliveryList: [], // 已交付信息列表
      feedBackList: [] // 客户反馈列表
    }
  },
  created () {
    this.initPage()
    this.getEnum()
    this.getCustomer()
  },
  components: {
    tab_1,
    tab_2,
    tab_3,
    tab_4,
    tab_5,
    tab_6,
    tab_7,
    tab_8,
    tab_9,
    tab_10,
    tab_11,
    tab_12,
    diagnose
  },
  computed: {
  },
  methods: {
    gotoBack () {
      this.$router.go(-1)
    },
    // 获取来源
    initPage () {
      this.customerId = this.$route.query.id
      if (this.$route.query.isCreate) {
        this.currentTab = '2'
        this.detailCurrent = '2'
        this.getContactList()
      } else {
        this.currentTab = '1'
      }
    },
    chooseTab (index) {
      if (index === this.detailCurrent) {
        return false
      } else {
        this.detailCurrent = index
        switch (index) {
          case '1':
            this.getCustomer()
            break
          case '2':
            this.getContactList()
            break
          case '3':
            this.getBudgetList()
            break
          case '4':
            this.getRequirementList()
            break
          case '5':
            this.getPlanList()
            break
          case '6':
            this.getBargainList()
            break
          case '7':
            this.getSalesContractList()
            break
          case '11':
            this.getToAllocationList()
            break
          case '8':
            this.getListToDelivery()
            break
          case '9':
            this.getListDelivery()
            break
          case '10':
            this.getFeedBackList()
            break
          case '12':
            this.getCommunicationList()
            break  
        }
        console.log(this.detailCurrent)
      }
    },
    // 获取客户基本信息
    getCustomer () {
      HRDCCustomerApi.GetCustomer({ id: this.customerId }).then(res => {
        if (res.data.success) {
          this.customerInfo = res.data.data
          this.customerName = res.data.data.name
        } else {
          this.$Message(res.data.message)
        }
      })
    },
    // 获取联系人列表
    getContactList () {
      HRDCCustomerApi.ContacterList({
        customerId: this.customerId,
        PageIndex: 0,
        PageSize: 100
      }).then(res => {
        if (res.data.success) {
          this.contact_arr = res.data.data
        } else {
          
          this.$Message.error({
            content: res.data.message,
            duration: 10,
            closable: true
          })
        }
      })
    },
    // 获取预算列表
    getBudgetList () {
      HRDCCustomerApi.BudgetList({
        customerId: this.customerId,
        PageIndex: 0,
        PageSize: 100
      }).then(res => {
        if (res.data.success) {
          this.budgetList = res.data.data
        } else {
          
          this.$Message.error({
            content: res.data.message,
            duration: 10,
            closable: true
          })
        }
      })
    },
    // 获取需求列表
    getRequirementList () {
      HRDCCustomerApi.RequirementList({
        customerId: this.customerId,
        PageIndex: 0,
        PageSize: 100
      }).then(res => {
        if (res.data.success) {
          this.requirementList = res.data.data
        } else {
          
          this.$Message.error({
            content: res.data.message,
            duration: 10,
            closable: true
          })
        }
      })
    },
    // 获取2D诊断表
    get2DDiagnoseInfo (val) {
      this.requirementId = val.id
      this.$refs.diagnose.modalOpen()
    },
    // 获取方案列表
    getPlanList () {
      HRDCCustomerApi.getPlanList({
        customerId: this.customerId,
        PageIndex: 0,
        PageSize: 100
      }).then(res => {
        if (res.data.success) {
          this.planList = res.data.data
        } else {
          
          this.$Message.error({
            content: res.data.message,
            duration: 10,
            closable: true
          })
        }
      })
    },
    // 获取合作信息
    getBargainList () {
      HRDCCustomerApi.getBargainList({
        customerId: this.customerId,
        PageIndex: 0,
        PageSize: 100
      }).then(res => {
        if (res.data.success) {
          this.bargainList = res.data.data
        } else {
          
          this.$Message.error({
            content: res.data.message,
            duration: 10,
            closable: true
          })
        }
      })
    },
    // 获取签约信息列表
    getSalesContractList () {
      HRDCCustomerApi.getSalesContractList({
        customerId: this.customerId,
        PageIndex: 0,
        PageSize: 100
      }).then(res => {
        if (res.data.success) {
          this.salesContractList = res.data.data
        } else {
          
          this.$Message.error({
            content: res.data.message,
            duration: 10,
            closable: true
          })
        }
      })
    },
    // 获取待分配交付信息
    getToAllocationList () {
      HRDCCustomerApi.GetToAllocationList({
        customerID: this.customerId,
        Status: 1
      }).then(res => {
        if (res.data.success) {
          this.toAllocationList = res.data.data
        } else {
          
          this.$Message.error({
            content: res.data.message,
            duration: 10,
            closable: true
          })
        }
      })
    },
    // 获取待交付信息列表
    getListToDelivery () {
      HRDCCustomerApi.GetListToDelivery({
        customerID: this.customerId,
        Status: 2
      }).then(res => {
        if (res.data.success) {
          this.toDeliveryList = res.data.data
        } else {
          
          this.$Message.error({
            content: res.data.message,
            duration: 10,
            closable: true
          })
        }
      })
    },
    // 获取已交付信息列表
    getListDelivery () {
      HRDCCustomerApi.GetDeliveryList({
        ID: this.customerId
      }).then(res => {
        if (res.data.success) {
          this.deliveryList = res.data.data
        } else {
          
          this.$Message.error({
            content: res.data.message,
            duration: 10,
            closable: true
          })
        }
      })
    },
    // 获取客户反馈列表
    getFeedBackList () {
      HRDCCustomerApi.GetFeedBackList({
        customerID: this.customerId
      }).then(res => {
        if (res.data.success) {
          this.feedBackList = res.data.data
        } else {
          
          this.$Message.error({
            content: res.data.message,
            duration: 10,
            closable: true
          })
        }
      })
    },
    // 获取沟通记录列表
    getCommunicationList () {
      HRDCCustomerApi.CommunicationList({
        customerId: this.customerId,
        PageIndex: 0,
        PageSize: 100
      }).then(res => {
        if (res.data.success) {
          this.communicationList = res.data.data
          this.communicationTotal = res.data.totalRows
        } else {
          
          this.$Message.error({
            content: res.data.message,
            duration: 10,
            closable: true
          })
        }
      })
    },
    getEnum () {
      let groupNames = 'customer.businesstype, sales.communicationtype, customer.size, customer.character'
      dataApi.getEnum({
        groupName: groupNames
      }).then((res) => {
        this.customerBusinesstype_arr = this.getItems(res.data, 'customer.businesstype')
        this.communicationtype = this.getItems(res.data, 'sales.communicationtype')
        this.sizeArr = this.getItems(res.data, 'customer.size')
        this.characterArr = this.getItems(res.data, 'customer.character')
      })
      // Common.getEnum(groupName, this.arrListDown)
    },
    getItems (arr, key) {
      let object = arr.find((item) => {
        return item.group === key
      })
      return object.items
    }
  }
}
</script>

<style lang="less">
.tab-style-hrdc> .ivu-tabs-card {
  .ivu-tabs-content {
    .ivu-tabs-tabpane {
      background: #fff;
      padding: 30px 16px 60px;
      border: 1px solid #dcdee2;
      border-top: none;
      .stepContent{
        position: relative;
        width: 100%;
        height: 100%;
      }
      .tab-footer{
        position: absolute;
        bottom: -40px;
        right: 0;
      }
    }
  }
  .ivu-select-disabled .ivu-select-selection {
    background-color: #fff;
    color: #333;
    border: none;
    cursor: auto;
    .ivu-select-arrow{
      display: none;
    }
  }
  .ivu-input[disabled], fieldset[disabled] .ivu-input{
    background-color: #fff;
    color: #333;
    border: none;
    cursor: auto;
  }
}
</style>
